import express from "express";
import {
  getProducts,
  getProductById,
  deleteProduct,
  createProduct,
  updateProduct,
  createProductReview,
  getTopProducts,
} from "../controller/productController.js";
import { protect, admin } from "../middleware/auth.js";
const router = express.Router();

//获取所有产品信息
//创建产品
router.route("/").get(getProducts).post(protect, admin, createProduct);

//获取排名前三的产品
router.route("/top").get(getTopProducts);

//根据商品id获取商品详情
//根据商品id删除商品
//根据产品id更新产品
router
  .route("/:id")
  .get(getProductById)
  .delete(protect, admin, deleteProduct)
  .put(protect, admin, updateProduct);

//添加评论
router.route("/:id/reviews").post(protect, createProductReview);

export default router;
